package comdemo.controller;


import comdemo.pojo.Coach;
import comdemo.pojo.Result;
import comdemo.service.ICoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 教练表 前端控制器
 * </p>
 *
 * @author 沈仁聪
 * @since 2025-08-19
 */
@RestController
@RequestMapping("/coach")
public class CoachController {

    @Autowired
    private ICoachService coachService;

    /**
     * <p>
     * 获取所有教练的信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-19
     */

    @GetMapping
    public Result getCoach() {
        List<Coach> list = coachService.list();
        return Result.success(list);
    }

    /**
     * <p>
     * 新增教练信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */
    @PostMapping("/add")
    public Result addCoach(@RequestBody Coach coach) {
        coachService.save(coach);
        return Result.success();
    }


    /**
     * <p>
     * 更新教练信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */

    @PostMapping("/update")
    public Result updateCoach(@RequestBody Coach coach) {
        coachService.updateById(coach);
        return Result.success();
    }

    /**
     * <p>
     * 删除教练信息
     * </p>
     *
     * @author 沈仁聪
     * @since 2025-08-20
     */
    @DeleteMapping("/delete")
    public Result deleteCoach(@RequestBody Coach coach) {
        coachService.removeById(coach);
        return Result.success();
    }
}
